package licode.unisop.platform.application.utils;

import licode.unisop.provider.conf.SiAssetType;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资源规则检测
 *
 * @author WR
 * @version 1.0
 * @date 2024-06-11 13:37
 */
@Component
public class RelationRule {
    private final Map<String, List<String>> RULES = new HashMap<>();

    @PostConstruct
    public void init() {
        List<String> items = new ArrayList<>();

        items.add(SiAssetType.AT_GROUP);
        items.add(SiAssetType.AT_REALM_GROUP);
        RULES.put(SiAssetType.AT_ROLE, items);

        items = new ArrayList<>();
        items.add(SiAssetType.AT_ROLE);
        RULES.put(SiAssetType.AT_GROUP, items);
    }

    public boolean isCanHold(String holdType, String targetType) {
        List<String> items = RULES.get(holdType);
        return null != items && items.contains(targetType);
    }
}
